#include "ICell.h"
#include <string>
//#include "cocos2d.h"
ICell::ICell(int type) : m_type(type)
{
}

ICell::~ICell(void)
{
	printf("");
}

CellFactory* CellFactory::s_sharedCellFactory = 0;
CellFactory* CellFactory::sharedCellFactory()
{
	if (s_sharedCellFactory == 0)
	{
		s_sharedCellFactory = new CellFactory();
	}
	return s_sharedCellFactory;
}

ICell* CellFactory::GetCell(unsigned int type)
{
	if (type < m_lowerBound || type > m_upperBound)
		return 0;
	CellMap::iterator it = m_cells.find(type);
	if (it == m_cells.end())
	{
		// create new cell type
		m_cells[type] = this->CreateCell(type);
		return m_cells[type];
	}
	else
	{
		return it->second;
	}
	return 0;
}

ICell* CellFactory::CreateCell(unsigned int type)
{
	return new ICell(type);
}

void CellFactory::SetCellTypeRange( unsigned int lower, unsigned int upper )
{
	m_lowerBound = lower;
	m_upperBound = upper;
	if (m_upperBound < m_lowerBound)
		m_upperBound = m_lowerBound;
}

CellFactory::CellFactory()
: m_lowerBound(0), m_upperBound(0)
{

}

